//
//  TravelTopicTableViewCell.m
//  穷游项目
//
//  Created by 刘建镇 on 14-12-29.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//
#import "macro.h"
#import "TravelTopicTableViewCell.h"

@implementation TravelTopicTableViewCell

- (void)dealloc
{
    [_cover release];
    [_text release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.view = [[UIView alloc] initWithFrame:CGRectMake(10, 10, SCREEN_WIDTH, SCREEN_HEIGHT*1/4 + 10)];
        [self.contentView addSubview:_view];
        [_view release];
        self.cover = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH - 20, SCREEN_HEIGHT*1/4)];
        [_view addSubview:_cover];
        [_cover release];
        self.text = [[UILabel alloc] initWithFrame:CGRectMake(10, _cover.frame.size.height + 5, SCREEN_WIDTH - 30, self.frame.size.height)];
        _text.backgroundColor = [UIColor clearColor];
        _text.numberOfLines = 0;
        _text.lineBreakMode = NSLineBreakByTruncatingTail;
        [_text setFont:[UIFont systemFontOfSize:13.0f]];
        [_text release];
        [_view addSubview:_text];
    }
    return  self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];//layout->布局
    NSDictionary *dic  = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:13.0f], NSFontAttributeName, nil];
    if (IOS_VERSION > 7.0) {
        CGRect rect = [self.text.text boundingRectWithSize:CGSizeMake(300, 1000) options:(NSStringDrawingUsesFontLeading|NSStringDrawingUsesLineFragmentOrigin) attributes:dic context:nil];
        [self.text setFrame:CGRectMake(self.text.frame.origin.x, self.text.frame.origin.y, self.text.frame.size.width, rect.size.height)];
    } else {
        CGFloat height = [self.text.text sizeWithFont:[UIFont systemFontOfSize:13.0f] constrainedToSize:CGSizeMake(300, 1000)].height;
        [self.text setFrame:CGRectMake(self.text.frame.origin.x, self.text.frame.origin.y, self.text.frame.size.width, height)];
    }
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
